import React, { Component } from 'react'
import { nanoid } from 'nanoid'
import store from '../../store/store';
import { AddTodos } from '../../store/actions/todo-action';
export default class Header extends Component {

  handleKeyUp = (e) => {
    const { keyCode, target } = e
    if (keyCode !== 13) {
      return
    }
    if(target.value===''){
      return
    }
    store.dispatch(AddTodos(nanoid(), target.value))
    target.value=''
  }
  render() {
    return (
      <div className='todo-header'>
        <input type="text" placeholder='请输入你的任务' onKeyUp={this.handleKeyUp} />
      </div>
    )
  }
}
